<?php

namespace App;

use Illuminate\Database\Eloquent\Model;


class Clubclass extends Model
{
    public function mentor(){
        return $this->belongsTo(Mentor::class);
    }//加载负责人类
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'title','cover_image','body','like_count','mentor_id'
    ];
        public function keytodata($keyname){
        return collect($keyname)->map(function($key){
            if(  !is_string($this->$key) && !is_int($this->$key)){
                if(  $this->$key  instanceof Carbon){
                    return [$key=>$this->$key->toFormattedDateString()];
                }
                else{
                    if($key == "mentor"){
                        return [$key=>$this->$key->name];
                    }else{
                        return [$key=>$this->$key->pluck('name')];
                    }

                }
            }
            return [$key=>$this->$key];
        })->collapse()->toArray();
      }
}
